package com.gs.common.websocket.config;

import com.gs.common.constant.Constant;
import com.gs.common.util.SecurityUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
 * WebSocket配置
 *
 * @author Mark sunlightcs@gmail.com
 */
@Configuration
public class WebSocketConfig extends ServerEndpointConfig.Configurator {
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        sec.getUserProperties().put(Constant.USER_KEY, SecurityUtils.getUserId());
    }

}